package br.eck.dialog;

import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;

/**
 * Cria uma Janela no jogo
 * 
 * @author Erick Zanardo
 *
 */
public class Window {
    /** SpriteSheet com o skin */
    private SpriteSheet skin;

    public Window(String skinRef) throws SlickException {
        skin = new SpriteSheet(skinRef, 10, 10);
    }

    public void drawWindow(int x, int y, int width, int height) {
        // Para contagem
        int cX = x;
        int cY = y;

        // Primeira borda
        skin.getSprite(DialogSkin.TOP_LEFT_CORNER.getX(),
                DialogSkin.TOP_LEFT_CORNER.getY()).draw(cX, cY);
        cX = cX + 10;
        while (cX < (x + width - 10)) {
            skin.getSprite(DialogSkin.TOP_CENTER.getX(),
                    DialogSkin.TOP_CENTER.getY()).draw(cX, cY);
            cX = cX + 10;
        }
        skin.getSprite(DialogSkin.TOP_RIGHT_CORNER.getX(),
                DialogSkin.TOP_RIGHT_CORNER.getY()).draw(cX, cY);
        cY = cY + 10;

        // O Meio da caixa
        while (cY < (y + height - 10)) {
            cX = x;

            skin
                    .getSprite(DialogSkin.LEFT.getX(),
                            DialogSkin.CENTER.getY()).draw(cX, cY);
            cX = cX + 10;

            while (cX < (x + width - 10)) {
                skin.getSprite(DialogSkin.CENTER.getX(),
                        DialogSkin.CENTER.getY()).draw(cX, cY);
                cX = cX + 10;
            }

            skin
                    .getSprite(DialogSkin.RIGHT.getX(),
                            DialogSkin.RIGHT.getY()).draw(cX, cY);

            cY = cY + 10;
        }

        // Ultima borda
        cX = x;
        skin.getSprite(DialogSkin.BOTTOM_LEFT_CORNER.getX(),
                DialogSkin.BOTTOM_LEFT_CORNER.getY()).draw(cX, cY);
        cX = cX + 10;
        while (cX < (x + width - 10)) {
            skin.getSprite(DialogSkin.BOTTOM_CENTER.getX(),
                    DialogSkin.BOTTOM_CENTER.getY()).draw(cX, cY);
            cX = cX + 10;
        }
        skin.getSprite(DialogSkin.BOTTOM_RIGHT_CORNER.getX(),
                DialogSkin.BOTTOM_RIGHT_CORNER.getY()).draw(cX, cY);
        cY = cY + 10;
    }

}
